
export class Stores {

    static wx_profile = null
    static wx_user = null
    static user = null

    static setUser(user) {
        this.user = user
        wx.setStorage({ key: 'user', data: user })
    }

    static setWxProfile(wx_profile) {
        this.wx_profile = wx_profile
        wx.setStorage({ key: 'wx_profile', data: wx_profile })
    }

    static getUser() {
        return this.user || wx.getStorageSync('user')
    }

    static getWxProfile() {
        return this.wx_profile || wx.getStorageSync('wx_profile')
    }

    static getWxUserInfo() {

        if (this.wx_user) return this.wx_user

        let profile = this.getWxProfile()
        return profile ? profile.userInfo : {}
    }

    static set(key, data) {
        wx.setStorage({ key, data })
    }

    static get(key) {
        wx.getStorageSync(key)
    }
}